{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/addons/builder/css/base.css" media="all">
<style>
    .layui-form-item {
        margin-bottom: 15px !important;
        clear: both;
        *zoom: 1;
    }
</style>
<body>
<div class="layui-fluid layui-anim layui-anim-downbit">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" id="form" action="{:url('save')}">
                {include file="public/arguments" /}
                <input type="hidden" name="id" value="{$Request.param.id|default=''}">
                <input type="hidden" name="pid" value="{$Request.param.pid|default=0}">
                {if $p_title }
                <div class="layui-form-item">
                    <label class="layui-form-label">上级菜单</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" value="{$p_title}" disabled="disabled"/>
                    </div>
                </div>
                {/if}
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" placeholder="请输入菜单名称" class="layui-input"
                               value="{$info?$info.title:''}"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>简称</label>
                    <div class="layui-input-block">
                        <input type="text" name="sub_title" placeholder="请输入菜单简称" class="layui-input"
                               value="{$info?$info.sub_title:''}"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>节点</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" name="name" autocomplete="off" placeholder="例如：menu/index "
                               class="layui-input"
                               value="{$info?$info.name:''}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">请使用驼峰命名</div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" autocomplete="off" placeholder="请输入排序，越小越靠前"
                               class="layui-input"
                               value="{$info?$info.sort:''}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>图标</label>
                    <div class="layui-input-block">
                        <input type="text" name="css" autocomplete="off" class="layui-input"
                               value="{$info?$info.css:''}">
                    </div>
                </div>
                {if !isset($info)}
                <div class="layui-form-item">
                    <label class="layui-form-label">自动构建Controller</label>
                    <div class="layui-input-block">
                        <input type="radio" name="autoController" value="" lay-filter="controller" title="关闭" checked>
                        <input type="radio" name="autoController" value="1" lay-filter="controller" title="单控制器">
                        <input type="radio" name="autoController" value="2" lay-filter="controller"
                               title="控制器+自动构建Table">
                    </div>
                    <div class="layui-form-mid layui-word-aux">开启后，将自动生成控制器</div>
                </div>
                <div class="controller" style="display:none;">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">* </span>控制器名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="className" placeholder="请填写控制器名称" autocomplete="off"
                                   class="layui-input auto_name" value="">
                        </div>
                        <div class="layui-form-mid layui-word-aux">控制器的名称，列如Test</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">* </span>命名空间</label>
                        <div class="layui-input-block">
                            <input type="text" name="classNamespace" placeholder="请填写命名空间" autocomplete="off"
                                   class="layui-input" value="app\admin\controller\">
                        </div>
                        <div class="layui-form-mid layui-word-aux">完整的命名空间，无需包含类名称</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">自动构建Model</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="autoModel" lay-skin="switch" lay-filter="model" lay-text="是|否"
                               value="1">
                    </div>
                    <div class="layui-form-mid layui-word-aux">开启后，将自动生成模型类</div>
                </div>
                <div class="model" style="display:none;">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">* </span>模型名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="modelName" placeholder="请填写模型名称" autocomplete="off"
                                   class="layui-input auto_name" value="">
                        </div>
                        <div class="layui-form-mid layui-word-aux">模型的名称，列如Test</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">* </span>命名空间</label>
                        <div class="layui-input-block">
                            <input type="text" name="modelNamespace" placeholder="请填写命名空间" autocomplete="off"
                                   class="layui-input" value="app\common\model\">
                        </div>
                        <div class="layui-form-mid layui-word-aux">完整的命名空间，无需包含类名称</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">* </span>表名</label>
                        <div class="layui-input-block">
                            <input type="text" name="dbName" placeholder="请填写表名" autocomplete="off"
                                   class="layui-input db_name" value="">
                        </div>
                        <div class="layui-form-mid layui-word-aux">Model类对应的数据库表名</div>
                    </div>
                </div>
                {/if}
            </form>
        </div>
    </div>

</div>
<div class="layui-footer" style="left: 0;">
    <button class="layui-btn" lay-filter="save" lay-submit formObj="#form">保存
    </button>
</div>
{include file="public/footer" /}
<script>
    layui.use('form', function () {
        var form = layui.form;
        $("#name").blur(function () {
            var value = $(this).val();
            var split = value.split('/');
            if (split[0]) {
                $(".auto_name").val(cap(split[0]));
                $(".db_name").val(split[0]);
            } else {
                $(".auto_name").val('');
                $(".db_name").val('');
            }
        });

        function cap(str) {
            return str.replace(/([a-z])/, function (match, value) {
                return value.toUpperCase();
            })
        }

        form.on('radio(controller)', function (data) {
            if (data.value) {
                if (data.value == '2') {
                    layer.msg('自动生成控制器+自动构建Table依赖数据表注释，请按结构合理配置')
                }
                $(".controller").show();
            } else {
                $(".controller").hide();
            }
        });

        form.on('switch(model)', function (data) {
            if (data.elem.checked) {
                $(".model").show();
            } else {
                $(".model").hide();
            }
        });


    });
</script>
</body>

</html>